const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    mode:"development",
    entry:path.resolve(__dirname,"src/index.js"),   //  "./src/index.js"
    output:{
        filename:"[name].js",
        path:path.resolve(__dirname,"dist/")
    },
    module:{
        rules:[
            {   // 处理CSS
                test:/\.(css|less|sass)$/i,
                use:["style-loader","css-loader","less-loader","sass-loader"]
            },
            {   // 处理图像
                test:/\.(png|jpg|jpeg|svg|webp)$/i,
                type:"asset/resource"  // file-loader
            },
            {   // 处理字体
                test: /\.(woff|woff2|eot|ttf|otf)$/i,
                type:"asset/resource"  // file-loader   
            },
            {
                test: /\.(js|jsx)$/i,
                exclude: path.resolve(__dirname,"node_modules"),
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env', '@babel/preset-react']
                    }
                }
            },
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename:"index.html",
            template:"src/index.html"
        })
    ],
    devServer: {
        contentBase: path.join(__dirname, 'dist'),
        compress: true,
        port: 3000
    }
};